<%--
    Document   : index
    Created on : 12.02.2010, 22:48:51
    Author     : Morfant
--%>

<%@page import="stud.cp.user.valueobjects.DBObjectType"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"
	language="java"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
<%@include file="/header.jsp"%>

<script type="text/javascript">     
        function cancelEvent(e){
            if (!e)
                if (window.event) e = window.event;
            else return;
            if (e.cancelBubble != null) e.cancelBubble = true;
            if (e.stopPropagation) e.stopPropagation();
            if (e.preventDefault) e.preventDefault();
            if (window.event) e.returnValue = false;
            if (e.cancel != null) e.cancel = true;
        }
        function isActionCanBePerform(obj,e){
            var inputs = document.getElementsByTagName("input");
            var i=0;
            var isAtLeastOneCheckBoxSelect=false;
            var checkBoxValue=-1;
            while((i<inputs.length)&&(!isAtLeastOneCheckBoxSelect)){
                if(inputs[i].type=="checkbox"){
                    if(inputs[i].checked){
                        isAtLeastOneCheckBoxSelect=true;
                        checkBoxValue=inputs[i].value;
                    }
                }
                i++;
            }
            if(!isAtLeastOneCheckBoxSelect){
                alert("Выберите хотя бы один объект!");
                cancelEvent(e);
            }else{
                obj.href=obj.href+"<%="&" + PluginConst.OBJECT_TYPE_ID + "="%>"+checkBoxValue;
            }
        }
        function checkOne(obj)
        {
            var grid = obj.parentNode.parentNode.parentNode;
            var inputs = grid.getElementsByTagName("input");
            for(var i=0;i<inputs.length;i++)
            {
                if (inputs[i].type =="checkbox")
                {
                    if(obj.checked && inputs[i] != obj && inputs[i].checked)
                    {
                        inputs[i].checked = false;
                    }
                }
            }
        }
    </script>

<body>
	<div class="page">
		<%@include file="/cap.jsp"%>
		<div id="main">
			<%@include file="/Designer/designer_cap.jsp" %>

			<h2>Список типов блюд.</h2>
			<table id="buttontable">
				<tr>
					<th>
						<div id="objectmenucontainer">
							<ul id="objectmenu">
								<li><a href="<%=response.encodeURL("dish-types-action.do")
										+ "?"
										+ PluginConst.SUBACTION
										+ "="  
										+ PluginConst.GET_ADD_PAGE%>">
										Добавить тип
									</a>
								</li>
							</ul>
						</div>
					</th>
					<th>
						<div id="objectmenucontainer">
							<ul id="objectmenu">
								<li><a href="<%=response.encodeURL("dish-types-action.do") 
										+ "?" 
										+ PluginConst.SUBACTION
										+ "="
										+ PluginConst.GET_EDIT_PAGE%>"
										onclick="isActionCanBePerform(this,event)">
										Редактировать тип
									</a>
								</li>
							</ul>
						</div>
					</th>
					<th>
						<div id="objectmenucontainer">
							<ul id="objectmenu">
								<li><a href="<%=response.encodeURL("dish-types-action.do") 
										+ "?" + PluginConst.SUBACTION
										+ "=" + PluginConst.GET_DELETE_PAGE%>"
										onclick="isActionCanBePerform(this,event)">
										Удалить тип
									</a>
								</li>
							</ul>
						</div> 
					</th>
				</tr>
 
			</table>
			<%
				List<DBObjectType> list = (List<DBObjectType>) request.getAttribute(PluginConst.OBJECT_TYPE_LIST);
					if ((list != null) && (list.size() > 0)) {
			%>
			<table>
				<tr>
					<th></th>
					<th>Тип блюда</th>
					<th>Описание</th>
				</tr>
				<%
					for (DBObjectType item : list) {
				%>
				<tr>
					<td><input type="checkbox"
						name="<%=PluginConst.OBJECT_TYPE_ID%>"
						value="<%=item.getObject_type_id()%>" onclick="checkOne(this)" />
					</td>
					<td>
						<a href="<%=response.encodeURL("dishes-action.do") 
							+ "?"
							+ PluginConst.SUBACTION
							+ "="
							+ PluginConst.GET_LIST + "&"
							+ PluginConst.OBJECT_TYPE_ID + "="
							+ item.getObject_type_id()%>">
							<%=item.getName()%>
						</a>
					</td> 
					<td>
						<textarea readonly id="description" rows="3" cols="40" name="show"><%=item.getDescription()%></textarea>
					</td>
				</tr>
				<%}%>
			</table>
			<%}%>
		</div>
	</div>
</body>
</html>
